<?php

namespace App\Exceptions;

use Exception;
use Illuminate\Http\Request;

class InternalException extends Exception
{
  protected $msgForUser;
  public function __construct(string $message = "",string $msgForUser = '系统内部错误', int $code = 400)
  {
    parent::__construct($message, $code);
    $this->msgForUser = $msgForUser;
  }
  public function render(Request $request)
  {
    if($request->expectsJson()){
      return response()->json(['code' => $this->code,'msg' => $this->msgForUser]);
    }
    return view('pages.error',['msg' => $this->msgForUser]);
  }
}
